package com.briup.day11;

/**
 * 时长类
 * @author lining
 * @date 2024/1/22 9:36
 */
public class Duration {
    //一次声明3个成员变量
    private int hours,minutes,seconds;

    public Duration() {

    }

    public Duration(int hours, int minutes, int seconds) {
        this.hours = hours;
        this.minutes = minutes;
        this.seconds = seconds;
    }
    public Duration(int totalSeconds) {
        //3661秒，就是1小时1分钟1秒  3600
        this.hours = totalSeconds / 3600; //1
        this.minutes = totalSeconds % 3600 / 60;//62  --> 1
        this.seconds = totalSeconds % 60;
    }

    public int getHours() {
        return hours;
    }

    public int getMinutes() {
        return minutes;
    }

    public int getSeconds() {
        return seconds;
    }

    public int getTotalSeconds(){
        //this表示区分成员变量和局部变量
        return hours * 3600 + minutes * 60 + seconds;
    }

    @Override
    public String toString() {
//        return super.toString();//没有，本质上使用父类中方法逻辑
//        return hours+":"+minutes+":"+seconds;
        //String  int类型-->String  3种方式转换：
       return String.join(":",String.valueOf(hours),minutes+"",Integer.toString(seconds));
    }
}
